using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Configuration;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class RowUpdatingEventPage : System.Web.UI.Page
{
    SqlDataSource sqlDataSource;
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
            FillData(GridView1);
    }

    void FillData(GridView gridView)
    {
        sqlDataSource = new SqlDataSource();
        sqlDataSource.ConnectionString =
        WebConfigurationManager.ConnectionStrings[
            "RecruitVietnamDbConnectionString"
            ].ConnectionString;
        sqlDataSource.SelectCommandType =
        SqlDataSourceCommandType.Text;
        sqlDataSource.SelectCommand = "select " +
        "RecruiterID,Email,CompanyName, "
        + "ContactName,Address "+
        " from tblRCAccounts where Activate=0 ";
        gridView.DataSource = sqlDataSource;
        gridView.DataBind();

    }

   bool Update(string recruiterID, GridView gridView)
    {
        bool update = false;
        sqlDataSource = new SqlDataSource();
        sqlDataSource.ConnectionString =
        WebConfigurationManager.ConnectionStrings[
            "RecruitVietnamDbConnectionString"
            ].ConnectionString;
        sqlDataSource.UpdateCommandType =
        SqlDataSourceCommandType.Text;
        sqlDataSource.UpdateCommand =
        "Update tblRCAccounts"+
        " set Activate=1 where " +
        "RecruiterID=@RecruiterID";
        sqlDataSource.UpdateParameters.Add(
        "RecruiterID", recruiterID);
        update = (sqlDataSource.Update() > 0);
        
        return update;
    }
    protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
    {
        if (Update(GridView1.Rows[e.RowIndex].Cells[0].Text, GridView1))
            FillData(GridView1);
    }
}
